import axios from "axios";

const apiClient = axios.create({
  baseURL: "http://localhost:8080", // API 基础路径
  timeout: 5000, // 请求超时时间
});

// 获取用户交易信息
export const getUserTrades = async (userId, status) => {
  try {
    const response = await apiClient.post("/trades/user", {
      userId,
      status,
    });
    return response.data; // 返回响应数据
  } catch (error) {
    console.error("获取用户交易信息失败:", error);
    throw error;
  }
};

//取消交易
export const cancelOrder = async (tradeId) => {
  const url = `http://localhost:8080/trades/seller/cancel/${tradeId}`;

  try {
    const response = await axios.put(url);

    // 处理成功的响应数据
    return response.data;
  } catch (error) {
    // 处理请求失败的错误
    console.error('请求取消订单失败:', error);
    return { status: 'error', message: error.response?.data?.message || error.message };
  }
};